package ttc.sftp.data;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import ttc.sftp.R;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LocalData {
	private List<VFile> listFiles;
	private VFile vFile; 
	private String path;

	public LocalData(String path) {
		
		if (path.compareTo("") == 0) {
			this.path = Environment.getExternalStorageDirectory() + "";
		}
		else
		{
			this.path=path;
		}
		vFile= new VFile(this.path);
		listFiles = vFile.getListFiles();
	}
	public VFile getFile()
	{
		return vFile;
	}
	public List<VFile> getListFiles() {
		sortByName();
		return listFiles;
	}
	public void sortByName() {
        Comparator<VFile> comperator = new Comparator<VFile>() {
            @Override
            public int compare(VFile object1, VFile object2) {
            	if(object1.IsDirectory()&&!object2.IsDirectory()) return -1;
            	else if(object2.IsDirectory()&&!object1.IsDirectory()) return 1;
                return object1.getName().compareToIgnoreCase(
                        object2.getName());
            }
        };
        Collections.sort(listFiles, comperator);
    }
}
